import { HeapNode, MaxHeap } from './MaxHeap'

/**
 * NOTE: 出队顺序和入队的顺序是无关的,
 * 操作系统中的任务的调度, 游戏中
 * 动态的队列
 * 使用堆实现队列: 出队和入队的时间复杂度是 O(logN)
 */

export interface Queue<E> {
  getSize(): number
  isEmpty(): boolean
  getFront(): E
  dequeue(): E
  enqueue(e: E): void
}

export class PriorityuQueue implements Queue<HeapNode> {
  private maxHeap: MaxHeap = new MaxHeap()

  public getSize(): number {
    return this.maxHeap.getSize()
  }

  public isEmpty(): boolean {
    return this.maxHeap.isEmpty()
  }

  public getFront(): HeapNode {
    return this.maxHeap.findMax()
  }

  public dequeue(): HeapNode {
    return this.maxHeap.extractMax()
  }

  public enqueue(e: HeapNode): void {
    return this.maxHeap.add(e)
  }
}
